<template>
	<view class="containner">
		<view class="header">
			<view class="user">
				<view class="head">
					<image :src="user.avatarUrl" class="head-img"></image>
				</view>
				<view class="info">
					<view class="name">{{ user.nickName }}</view>
					<!-- <view class="button">
						<u-icon name="edit-pen" labelPos="left" color="#fff" size="14"></u-icon>
						<u-icon name="arrow-right" labelPos="left" color="#fff" size="14" label="完善个人资料"
							labelColor="#fff"></u-icon>
					</view> -->
				</view>
			</view>
		</view>

		<view class="box">
			<view class="to-college">
				<view>距离高考还有</view>
				<view>
					<u-count-down :time="time" format="DD:HH:mm:ss" autoStart 
						@change="onChange" @finish="onFinish">
						<view class="time">
							<text class="time__item">{{ timeData.days }}天</text>
							<text
								class="time__item">{{ timeData.hours>10?timeData.hours:'0'+timeData.hours}}时</text>
							<text class="time__item">{{ timeData.minutes }}分</text>
							<text class="time__item">{{ timeData.seconds }}秒</text>
						</view>
					</u-count-down>
				</view>
			</view>
			<view class="study-achievement">
				<view class="line"></view>
				<view class="item">
					<view class="title">坚持天数</view>
					<view class="value">{{ studyDay }}</view>
				</view>
				<view class="item">
					<view class="title">皇冠个数</view>
					<view class="value">{{ crownNum }} <image src="http://qiniu.disciplineeducation.com/studyIcons/crown-light.png" class="crown-total-icon">
						</image>
					</view>
				</view>
			</view>

			<view class="buttons">
				<view class="item" @click="toBrush(1)">开始刷题</view>
				<view class="item" @click="toBrush(2)">错题本</view>
			</view>

		</view>


	</view>
</template>

<script>
	export default {
		data() {
			return {
				timeData: {},
				studyDay:'0',
				crownNum:'0',
				user:{},
				time:0
			}
		},
		onShareAppMessage(res){
			return this.$utils.onShareAppMessage();
		},
		onLoad() {
			this.getInfo();
			this.user = uni.getStorageSync('user')
		},
		methods: {
			async getInfo(){
				const res = await this.$http.get(`/wechatmini/study/summary`);
				if(res.code == 0){
					this.studyDay = res.data.study_day;
					this.crownNum = res.data.crown_num;
					this.time = res.data.nemt_countdown * 1000
				}
			},
			toBrush(type) {
				uni.navigateTo({
					url: `/pages/brush/index?type=${type}`
				})
			},
			onChange(e) {
				this.timeData = e
			},
			onFinish(){
				
			}
		}
	}
</script>
<style>
	page {
		background-color: #f7f9ff;
	}
</style>
<style scoped lang="scss">
	.header {
		overflow: hidden;
		padding-top: 40rpx;
		padding-bottom: 70rpx;


		.user {
			display: flex;
			flex-wrap: wrap;
			width: 80%;
			margin: 0 auto;
			margin-top: 30rpx;

			.head-img {
				width: 110rpx;
				height: 110rpx;
				border-radius: 50%;
			}

			.info {
				margin-left: 20rpx;
				display:flex;
				align-items: center;
				.name {
					color: #9198b7;
					font-weight: bold;
				}

				.button {
					display: flex;
					flex-wrap: wrap;
					margin-top: 20rpx;
					background-color: #9595a4;
					border-radius: 40rpx;
					padding: 10rpx;
					opacity: 0.5;
				}
			}

		}
	}

	.box {
		margin: 30rpx;

		.to-college {
			display: flex;
			justify-content: space-between;
			background-color: #eef1ff;
			padding: 20rpx 30rpx;
			line-height: 1;
			border-radius: 20rpx;
			margin-bottom: -10rpx;
			position: relative;
			z-index: 10;
		}

		.study-achievement {
			display: flex;
			background-color: #cacfe0;
			border-radius: 20rpx;
			align-items: center;
			position: relative;

			.line {
				height: 150rpx;
				width: 1rpx;
				background-color: #dce0eb;
				position: absolute;
				left: 50%;
			}

			.item {
				width: 50%;
				padding: 50rpx 0;
				text-align: center;

				.value {
					color: #575757;
					font-size: 34rpx;
					font-weight: bold;
					margin-top: 60rpx;
				}

				.crown-total-icon {
					width: 40rpx;
					height: 40rpx;
					vertical-align: middle;
					margin-left: 10rpx;
				}
			}

		}

		.buttons {
			display: flex;
			margin-top: 30rpx;

			.item {
				width: 50%;
				height: 400rpx;
				border-radius: 20rpx;
				line-height: 400rpx;
				text-align: center;
			}

			.item:first-child {
				background-color: #c8e0de;
				margin-right: 15rpx
			}

			.item:last-child {
				background-color: #d7d2e1;
				margin-left: 15rpx;
			}
		}
	}
</style>
